//
// Created by cube on 2020/10/23.
//
#include <gtest/gtest.h>
#include <iostream>
#include "../Container/ThreadContainer.h"


TEST(Container_TEST,CPriority_Queue){
    CPriority_Queue<int> pp;
    pp.push(40);
    pp.push(4);
    pp.push(10);
    pp.push(90);
    pp.push(0);
    while (!pp.empty()){
        std::cout<<pp.front()<<std::endl;
        pp.pop_front();
    }
}

TEST(Container_TEST,TContainer){
    TContainer<int,std::list<int>> bbb;

    std::thread t([&](){
        for(int i=0;i<10000;i++){
            bbb.lock()->push_back(i*10);
        }
    });

    std::thread t1([&](){
        for(int i=0;i<10000;i++){
            bbb.lock()->push_back(i*100);
        }
    });

    t.join();
    t1.join();

    std::cout<<bbb.size()<<std::endl;
}

TEST(Container_TEST,TMap){

    TMap<int,int> map;
    if(true){
        auto l = map.lock_guard();
        map[3] = 4;
        map[8] = 4;
        map[10] = 7;
        map[1] = 7;
        map[0] = 7;
        map[9] = 7;
        map[20] = 7;
    }

    map.lock()->insert(std::pair(300,2));

    std::pair<int,int> item;
    map.getOne(item);
    std::cout<<item.first<<" "<<item.second<<std::endl;

    auto l = map.getAll(3);
    for(auto p : l)std::cout<<p.first<<"  "<<p.second<<std::endl;

    std::cout<<"--"<<std::endl;
    int i = 0;
    while (map.ergodic_at(i++,item))std::cout<<item.first<<"  "<<item.second<<std::endl;

}

TEST(Container_TEST,TSet){
    TSet<int> set;
    if(true){
        auto l = set.lock_guard();
        for(int i=0;i<10;i++)
            set.insert(i);
    }

    int item;
    set.getOne(item);
    std::cout<<item<<std::endl;

    auto l = set.getAll(3);
    for(auto p : l)std::cout<<p<<std::endl;

    std::cout<<"--"<<std::endl;
    int i = 0;
    while (set.ergodic_at(i++,item))std::cout<<item<<std::endl;

}

TEST(Container_TEST,TList){
    TList <int> list;
    if(true){
        auto l = list.lock_guard();
        for(int i=0;i<10;i++){
            list.push_back(i);
        }
    }

    int item;
    list.getOne(item);
    std::cout<<item<<" "<<item<<std::endl;

    auto l = list.getAll(3);
    for(auto p : l)std::cout<<p<<std::endl;

    std::cout<<"--"<<std::endl;
    int i;
    while (list.ergodic_at(i++,item))std::cout<<item<<std::endl;

}